#include "../source/server.hpp"

void OnConnected(const PtrConnection &conn) 
{
    DBG_LOG("NEW CONNECTION:%p", conn.get());
}

void OnClosed(const PtrConnection &conn) 
{
    DBG_LOG("CLOSE CONNECTION:%p", conn.get());
}

void OnMessage(const PtrConnection &conn, Buffer *buf) 
{
    DBG_LOG("%s", buf->GetHeadIdleSize());
    buf->MoveReadOffset(buf->GetHeadIdleSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());
}

int main()
{
    TcpServer server(8500);
    std::cout<<"TcpServer"<<std::endl;
    
    server.SetThreadCount(2);
    std::cout<<"SetThreadCount"<<std::endl;

    //server.EnableInactiveRelease(10);
    server.SetClosedCallback(OnClosed);
    std::cout<<"SetClosedCallback"<<std::endl;

    server.SetConnectedCallback(OnConnected);
    std::cout<<"SetConnectCallback"<<std::endl;

    server.SetMessageCallback(OnMessage);
    std::cout<<"SetMessageCallback"<<std::endl;

    server.Start();
    return 0;
}